Use get_running_loop() instead of get_event_loop() #1774
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR proposes to change
get_event_loop()
toget_running_loop()
inprompt_toolkit/application.py
to improve compatibility on Windows.As mentioned in other places of the prompt_toolkit codebase,
get_running_loop()
is the recommended way to get the event loop since Python 3.7, because it returns the running loop for the current context instead of strictly the default loop.This is important for prompt_toolkit to work properly on Windows, where the default loop may not be compatible. Using
get_running_loop()
can avoid potential issues with an incompatible default loop.The usage of get_event_loop() in
prompt_toolkit/application.py
seems to be leftover from early development, and was likely forgotten to be changed when adding Windows support. All other occurrences have been updated touse get_running_loop()
.Replacing this instance of
get_event_loop()
withget_running_loop()
should improve portability without introducing side effects. It follows the prompting_toolkit's design goal of being cross-platform compatible.Therefore, I propose we make this change to remain consistent with the rest of the codebase and avoid potential bugs on Windows. Please consider merging this PR to use
get_running_loop()
instead ofget_event_loop()
in application.py. Let me know if any changes are necessary. Thanks!